package com.jcli._定时提醒;

import javax.swing.*;
import java.awt.*;

/**
 * 1.窗口置顶
 * @author li
 */
public class TopMostWindowExample {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> createAndShowGUI());
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("Top Most Window Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton toggleButton = new JButton("Toggle Top Most");
        toggleButton.addActionListener(e -> toggleTopMost(frame));

        frame.add(toggleButton);
        frame.setSize(300, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    private static void toggleTopMost(JFrame frame) {
        boolean currentTopMost = frame.isAlwaysOnTop();
        frame.setAlwaysOnTop(!currentTopMost);
    }
}
